﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace VPLink2013.Framework
{
    [DataContract]
    public class NewsItem
    {
        [DataMember(Name = "Id", Order = 1)]
        [XmlAttribute("id")]
        public string Id { get; set; }

        [DataMember(Name = "Name", Order = 2)]
        [XmlAttribute("nom")]
        public string Name { get; set; }

        [DataMember(Name = "LastModified", Order = 3)]
        [XmlElement("DerniereModif")]
        public string LastModified { get; set; }

        [DataMember(Name = "LastVisited", Order = 4)]
        [XmlElement("DerniereVisite")]
        public string LastVisited { get; set; }

        public NewsItem(string id, string name, string lastMidified, string lastVisited)
            : this(id, name, lastMidified)
        {
            this.LastVisited = LastVisited;
        }

        public NewsItem(string id, string name, string lastMidified)
            : this(id, name)
        {
            this.LastModified = lastMidified;
        }

        public NewsItem(string id, string name)
            : this(id)
        {
            this.Name = name;
        }
        public NewsItem(string id)
        {
            this.Id = id;
            this.LastModified = DateTime.Now.ToString();
            this.LastVisited = DateTime.MinValue.ToString();
        }
        public NewsItem() { }
    }

    [DataContract]
    public class NewsList
    {
        [DataMember(Name = "Id", Order = 1)]
        [XmlAttribute("guid")]
        public string Id { get; set; }

        [DataMember(Name = "Name", Order = 2)]
        [XmlAttribute("name")]
        public string Name { get; set; }

        [DataMember(Name = "Url", Order = 3)]
        [XmlAttribute("url")]
        public string Url { get; set; }

        [DataMember(Name = "listItems", Order = 4)]
        [XmlElement("item")]
        public List<NewsItem> listItems { get; set; }


        public NewsList(string id, string name)
            : this(id)
        {
            this.Name = name;
        }

        public NewsList(string id)
        {
            this.Id = id;
            listItems = new List<NewsItem>();
        }
        public NewsList()
        {
        }
    }

    [DataContract]
    public class WorkSpace
    {
        [DataMember(Name = "Name", Order = 1)]
        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlAttribute("url")]
        public string Url { get; set; }

        [DataMember(Name = "NewsSources", Order = 2)]
        [XmlElement("List")]
        public List<NewsList> NewsSources { get; set; }

        public WorkSpace(string name)
        {
            NewsSources = new List<NewsList>();
            this.Name = name;
        }
        public WorkSpace()
        {
        }
    }

    [DataContract]
    [XmlRoot("Notifications"), XmlType("NotificationsItem")]
    public class NotificationsItem
    {
        [DataMember(Name = "WorkSpace", Order = 1)]
        [XmlElement("Espace")]
        public List<WorkSpace> WorkSpaces { get; set; }
    }
}
